package com.lq.learningTest.encapsulation;

import java.util.Scanner;

public class Ticket {

    private Queue queue = new Queue();

    private int startNumber = 100;

    private Scanner scanner = new Scanner(System.in);

    /**
     * 增加队列中的数值
     * @param ticketNumber
     */
    public void pushTicket(int ticketNumber){
        for (int i = 0; i < ticketNumber; i++) {
            startNumber += i;
            queue.add(startNumber);
        }
    }

    /**
     * 获取票号，如果队列中为空就增加数值进队
     * @return
     */
    public Integer getTicket(){
        if(queue.empty()){
            System.out.println("号码已经被全部领取，需要继续释放号码！");
            System.out.println("请输入释放号码的个数：");
            Integer number = scanner.nextInt();
            pushTicket(number);
        }
        return queue.poll();
    }

    /**
     * 票据系统的主程序
     */
    public void run(){
        while (true){
            System.out.println("请输入您的名字：");
            String name = scanner.next();
            Integer ticket = getTicket();
            System.out.println("尊敬的【"+name + "】，您的号码是：" + ticket + "。");
        }
    }
}


